<?php

/**
 * This is the model class for table "incidente".
 *
 * The followings are the available columns in table 'incidente':
 * @property integer $id
 * @property integer $idmotivo
 * @property string $direccion
 * @property integer $tipo
 * @property double $x
 * @property double $y
 * @property string $estado
 * @property string $descripcion
 * @property string $fecha
 * @property integer $distrito
 *
 * The followings are the available model relations:
 * @property Distrito $distrito0
 * @property CausaIncidente $idmotivo0
 * @property TipoIncidente $tipo0
 * @property Persona[] $personas
 */
class Incidente extends CActiveRecord
{
   
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Incidente the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'incidente';
	}

        	public function tipoIncidente()
        
	{
                                       
		return  Tipo::model()->findByPk($this->tipo)->descripcion;
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('idmotivo, direccion, tipo, x, y, distrito', 'required'),
			array('idmotivo, tipo, distrito', 'numerical', 'integerOnly'=>true),
			array('x, y', 'numerical'),
			array('direccion', 'length', 'max'=>50),
			array('estado', 'length', 'max'=>10),
			array('descripcion', 'length', 'max'=>100),
			array('fecha', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, idmotivo, direccion, tipo, x, y, estado, descripcion, fecha, distrito', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'distrito0' => array(self::BELONGS_TO, 'Distrito', 'distrito'),
			'idmotivo0' => array(self::BELONGS_TO, 'CausaIncidente', 'idmotivo'),
			'tipo0' => array(self::BELONGS_TO, 'TipoIncidente', 'tipo'),
			'personas' => array(self::HAS_MANY, 'Persona', 'incidente'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'idmotivo' => 'Idmotivo',
			'direccion' => 'Direccion',
			'tipo' => 'Tipo',
			'x' => 'X',
			'y' => 'Y',
			'estado' => 'Estado',
			'descripcion' => 'Descripcion',
			'fecha' => 'Fecha',
			'distrito' => 'Distrito',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('idmotivo',$this->idmotivo);
		$criteria->compare('direccion',$this->direccion,true);
		$criteria->compare('tipo',$this->tipo);
		$criteria->compare('x',$this->x);
		$criteria->compare('y',$this->y);
		$criteria->compare('estado',$this->estado,true);
		$criteria->compare('descripcion',$this->descripcion,true);
		$criteria->compare('fecha',$this->fecha,true);
		$criteria->compare('distrito',$this->distrito);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}